#ifndef _MODULE_HPP
#define _MODULE_HPP

#include <lua.hpp>
#include "Args.hpp"
#include "Return.hpp"
#include "../EntityManager.hpp"

namespace lua
{

class Module;
typedef Return(*_lua_CFunction)(Module *module, Args args);
	
class Module
{
public:
	static Module* create(const char *name);
	bool destroy();
	void loadDefaultLibraries(bool os = true, bool io = true, bool base = true, bool table = true, bool string = true, bool math = true);
	void registerFunction(const char *libName, const char *funcName, _lua_CFunction func);
	bool loadFile(const char *filename);
	bool dostring(const char *str);
	Return callLuaFunction(const char *name, Args args = Args(currentModule));
	void clearStack();

	inline lua_State* getLuaVM(){ return mLuaVM; }
	inline const char* getName(){ return mName; }

	static Module *currentModule;
	friend class ModuleManager;
private:
	Module(const char *name);
	~Module();
private:
	const char *mName;
	lua_State *mLuaVM;
	EntityManager mEntityManager;
};

}

#endif